package com.whut.rssReader.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLiteHelp extends SQLiteOpenHelper {

	public MySQLiteHelp(Context context) {
		
		super(context, RssInfo.DATABASE_NAME, null, RssInfo.DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		
		String sort_table = "create table if not exists " + RssInfo.SORT_TABLE + "(" + 
		             RssInfo.SORT_ID+ " INTEGER PRIMARY KEY AUTOINCREMENT," + 
				     RssInfo.SORT_NAME + " text," + 
		             RssInfo.SORT_DATE  + "text" + ");";
		
		String resource_table = "create table IF NOT EXISTS " + RssInfo.RESOURCE_TABLE + "(" + 
		              RssInfo.RESOURCE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
				      RssInfo.RESOURCE_NAME + " text," + 
		              RssInfo.RESOURCE_LINK + " text," + 
		              RssInfo.RESOURCE_DESCRIPTION + " text," + 
				      RssInfo.RESOURCE_ICON + " text," + 
		              RssInfo.RESOURCE_DATE + " text," + 
				      RssInfo.RESOURCE_SHOW  + " text," + 
		              RssInfo.RESOURCE_SORT +" text"  +");";
		
		String favorite_table = "create table IF NOT EXISTS " + RssInfo.FAVORITE_TABLE + "(" + 
	              RssInfo.FAVORITE_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
			      RssInfo.FAVORITE_TITLE + " text," + 
	              RssInfo.FAVORITE_LINK + " text," + 
	              RssInfo.FAVORITE_DESCRIPTION + " text," + 
	              RssInfo.FAVORITE_DATE + " text," + 
	              RssInfo.FAVORITE_PUBLISHTIME +" text"  +");";
		
		String news_table = "create table IF NOT EXISTS " + RssInfo.NEWS_TABLE + "(" + 
	              RssInfo.NEWS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
			      RssInfo.NEWS_TITLE + " text," + 
	              RssInfo.NEWS_LINK + " text," + 
	              RssInfo.NEWS_DESCRIPTION + " text," + 
	              RssInfo.NEWS_RESOURCE + " INTEGER," + 
	              RssInfo.NEWS_DATE + " text," + 
	              RssInfo.NEWS_READ +" INTEGER"  +");";
		
		String recommand_table = "create table IF NOT EXISTS " + RssInfo.RECOMMAND_TABLE + "(" + 
	              RssInfo.RECOMMAND_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
			      RssInfo.RECOMMAND_TITLE + " text," + 
	              RssInfo.RECOMMAND_LINK + " text," + 
	              RssInfo.RECOMMAND_SORT +" text"  +");";
		
System.out.println(recommand_table);
		
		db.execSQL(sort_table);
		db.execSQL(resource_table);
		db.execSQL(favorite_table);
		db.execSQL(news_table);
		db.execSQL(recommand_table);

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

}
